package com.woniuxy.propertyjava.controller;



import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.Park;
import com.woniuxy.propertyjava.entity.Patrolplan;
import com.woniuxy.propertyjava.entity.ResponseResult;
import com.woniuxy.propertyjava.service.ParkService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Park)表控制层
 *
 * @author makejava
 * @since 2022-07-06 10:08:10
 */
@RestController
@RequestMapping
public class ParkController {
    /**
     * 服务对象
     */
    @Resource
    private ParkService parkService;

    /**
     * 分页查询
     *
     * @param park        筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @PostMapping("/park/{pageIndex}/{pageSize}")
    public ResponseResult<PageBean<Park>> queryByPage(@RequestBody Park park,
                                                      @PathVariable int pageIndex,
                                                      @PathVariable int pageSize) {

        PageBean<Park> pageBean = new PageBean<>();

        pageBean=parkService.queryByPage(park,pageIndex,pageSize);
        ResponseResult<PageBean<Park>> responseResult = new ResponseResult<>();
        responseResult.setCode(200);
        responseResult.setMsg("查询成功");
        responseResult.setData(pageBean);
        return responseResult;

    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/park/{id}")
    public ResponseResult<Park> queryById(@PathVariable("id") Integer id) {
        return new ResponseResult<>(200,"ok", parkService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param park 实体
     * @return 新增结果
     */
    @PostMapping("/park")
    public ResponseResult<Park> add(@RequestBody Park park) {

        return new ResponseResult<>(200,"ok",parkService.insert(park));
    }

    /**
     * 编辑数据
     *
     * @param park 实体
     * @return 编辑结果
     */
    @PutMapping("/park")
    public ResponseResult<Park> edit(@RequestBody Park park) {
        return new ResponseResult<>(200,"ok",parkService.update(park));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/park/{id}")
    public ResponseResult<Boolean> deleteById(@PathVariable Integer id) {
        return new ResponseResult<>(200,"ok",parkService.deleteById(id));
    }

}

